package com.pinyougou.manager.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.common.PageResult;
import com.pinyougou.pojo.TypeTemplate;
import com.pinyougou.service.TypeTemplateService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/typeTemplate")
public class templateController
{
    @Reference(timeout = 10000)
    private TypeTemplateService typeTemplateService;

    @GetMapping("/findByPage")
    public PageResult findByPage(TypeTemplate typeTemplate, Integer page, @RequestParam(defaultValue = "3") Integer rows)
    {
        try
        {
            return typeTemplateService.findByPage(typeTemplate, page, rows);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @PostMapping("/save")
    public boolean save(@RequestBody TypeTemplate template)
    {
        try
        {
            typeTemplateService.save(template);
            return true;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return false;
    }

    @PostMapping("/update")
    public boolean update(@RequestBody TypeTemplate typeTemplate)
    {
        try
        {
            typeTemplateService.update(typeTemplate);
            return true;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return false;
    }
    @GetMapping("/delete")
    public boolean delete(Long[] ids)
    {
        try
        {
            typeTemplateService.deleteAll(ids);
            return true;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return false;
    }

    /** 查找模板的id和name的集合 */
    @GetMapping("/findTypeTemplateList")
    public List<Map<String,Object>> findTypeTemplateList()
    {
        return typeTemplateService.findIdNameList();
    }
}